﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BUS;
using Microsoft.Phone.Controls;

namespace ProjectM2Work.Pages
{
    public partial class PageChuong03 : PhoneApplicationPage
    {
        public PageChuong03()
        {
            InitializeComponent();

            videoToi.Source = new Uri(PublicAndStatic.URLHost +"/DictVideo/" + "video_bai_giang.wmv", UriKind.Absolute);
            videoToi.Position = new TimeSpan(0, 0, 0, 0);
            videoToi.CurrentStateChanged += new RoutedEventHandler(videoToi_CurrentStateChanged);
            videoToi.MediaEnded += new RoutedEventHandler(VideoToi_MediaEnded);

        }

       

        private void VideoToi_MediaEnded(object sender, RoutedEventArgs e)
        {
            videoToi.Stop();
        }

     

        private void StateChangeMedia(MediaElement video, Image img)
        {
            if (video.CurrentState == MediaElementState.Playing)
            {
                BitmapImage tn = new BitmapImage();
                tn.SetSource(
                    Application.GetResourceStream(new Uri(@"/ProjectM2Work;component/images/btn_pause_enable.png",
                                                          UriKind.Relative)).Stream);
                img.Source = tn;
            }
            else if (video.CurrentState == MediaElementState.Paused)
            {
                BitmapImage tn = new BitmapImage();
                tn.SetSource(
                    Application.GetResourceStream(new Uri(@"/ProjectM2Work;component/images/btn_play_enable.png",
                                                          UriKind.Relative)).Stream);
                img.Source = tn;
            }
            else if (video.CurrentState == MediaElementState.Paused)
            {
                BitmapImage tn = new BitmapImage();
                tn.SetSource(
                    Application.GetResourceStream(new Uri(@"/ProjectM2Work;component/images/btn_play_enable.png",
                                                          UriKind.Relative)).Stream);
                img.Source = tn;
            }
        }




        private void videoToi_CurrentStateChanged(object sender, RoutedEventArgs e)
        {
            StateChangeMedia(videoToi, imgToi);
        }

        private void btn_mucluc_MouseLeave(object sender, MouseEventArgs e)
        {
            App.ZoomInImage(sender);
        }

        private void btn_mucluc_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            App.ZoomOutImage(sender);
        }

        private void btn_mucluc_MouseMove(object sender, MouseEventArgs e)
        {
            App.ZoomOutImage(sender);
        }

        private void btn_mucluc_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/PageBaiGiang.xaml", UriKind.Relative));
        }

        private void imgToi_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            StateChangeTagImage(videoToi);
        }
        private void StateChangeTagImage(MediaElement video)
        {
            if (video.CurrentState == MediaElementState.Paused || video.CurrentState == MediaElementState.Stopped)
            {
                video.Play();
            }
            else
            {
                if (videoToi.CurrentState == MediaElementState.Playing)
                {
                    video.Pause();
                }
            }
        }

    }
}